package com.tjetc.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration

public class acrossconfig implements WebMvcConfigurer {



    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")// 针对所有路径应用跨域配置
                .allowedOrigins("*")// 允许所有来源
                .allowedHeaders("*");// 允许所有请求头
//                .allowedMethods("*")// 允许所有请求方法

//                .allowedOrigins("http://example.com", "http://another-example.com") // 明确列出允许的源
//                .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的HTTP方法
//                .allowCredentials(true) // 允许携带凭证
//                .maxAge(3600); // 预检请求的有效期（秒）
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload")
                .addResourceLocations("classpath:/static/");
    }
}
